package top.huntwolf.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.spring.web.json.Json;
import top.huntwolf.admin.common.JsonResult;
import top.huntwolf.admin.common.enums.CodeMsg;
import top.huntwolf.admin.pojo.Subject;
import top.huntwolf.admin.pojo.subject.FirstSubjectWithBook;
import top.huntwolf.admin.service.SubjectService;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/subject")
@CrossOrigin
@Api(description = "书本分类控制器")
public class SubjectController {

    @Autowired
    SubjectService subjectService;


    @GetMapping("")
    public JsonResult getList() {
        List list = subjectService.getList();
        return JsonResult.success(list);
    }

    @GetMapping("get")
    @ApiOperation("查看分类列表，并且可以查看各分类下的书本")
    public JsonResult<List<FirstSubjectWithBook>> getListInfo(){
        return JsonResult.success(subjectService.getListInfo());
    }

    // ----------------------------------------------------- 以下为热搜功能 ----------------------------------------------
    @GetMapping(value = {"hotSort/{limit}","hotSort"})
    @ApiOperation(value = "获取指定个热门搜索分类，默认为6")
    public JsonResult getHotSort(@PathVariable(value = "limit",required = false) Integer limit) {

        // 如果不传参，默认为6个热门热搜
        if (limit == null) {
            limit = 6;
        }

        List hostSorts = subjectService.getHotSort(limit);
        return JsonResult.success(hostSorts);
    }

}
